//Tracker.vn  
//CopyRight By Tracker Group
 using System;
 using System.Text;
using System.Data;

namespace tracker.Models.DTO
{
   public class EUserLogin
   {
	 public EUserLogin()
	 {
	 }

     #region FIELD DEFINE
     public const string FIELD_USERID = "UserID";
     public const string FIELD_TIMEZONEMINUTE = "TimeZoneMinute";
     public const string FIELD_SECURITYCODE = "SecurityCode";
     public const string FIELD_USERNAME = "Username";
     public const string FIELD_PASSWORD = "Password";
     public const string FIELD_FULLNAME = "Fullname";
     public const string FIELD_ADDRESS = "Address";
     public const string FIELD_PHONE = "Phone";
     public const string FIELD_CELLPHONE = "Cellphone";
     public const string FIELD_EMAIL = "Email";
     public const string FIELD_USERGROUPID = "UserGroupID";
     public const string FIELD_CREATEBY = "CreateBy";
     public const string FIELD_MODIFYBY = "ModifyBy";
     public const string FIELD_CREATEDATE = "CreateDate";
     public const string FIELD_MODIFYDATE = "ModifyDate";
     public const string FIELD_NUMBEROFDEVICE = "NumberOfDevice";
     public const string FIELD_STARTDATE = "StartDate";
     public const string FIELD_ENDDATE = "EndDate";
     public const string FIELD_NOTE = "Note";
     public const string FIELD_STATUS = "Status";
     public const string FIELD_PARENTCODE = "ParentCode";
     #endregion

     private int _UserID ;
	 private string _Username ;
     private string _SecurityCode;
	 private string _Password ;
	 private string _Fullname ;
	 private string _Address ;
	 private string _Phone ;
     private string _Cellphone;
	 private int _UserGroupID ;
     private int _NumberOfDevice;
	 private string _CreateBy ;
	 private string _ModifyBy ;
     private string _Email;
     private int _TimeZoneMinute;
	 private DateTime _CreateDate ;
	 private DateTime _ModifyDate ;
	 private DateTime _StartDate ;
	 private DateTime _EndDate ;
	 private string _Note ;
	 private int _Status ;
     private string _ParentCode;

     public string ParentCode
     {
         get { return _ParentCode; }
         set { _ParentCode = value; }
     }
     public string Cellphone
     {
         get { return _Cellphone; }
         set { _Cellphone = value; }
     }
     public int TimeZoneMinute
     {
         get { return _TimeZoneMinute; }
         set { _TimeZoneMinute = value; }
     }
	 public int UserID
	 {
	    get { return _UserID ; }
	    set { _UserID = value ; }
	 }
	 public string Username
	 {
	    get { return _Username ; }
	    set { _Username = value ; }
	 }
     public string SecurityCode
     {
         get { return _SecurityCode; }
         set { _SecurityCode = value; }
     }
	 public string Password
	 {
	    get { return _Password ; }
	    set { _Password = value ; }
	 }
     public string Email
	 {
         get { return _Email; }
         set { _Email = value; }
	 }
	 public string Fullname
	 {
	    get { return _Fullname ; }
	    set { _Fullname = value ; }
	 }
	 public string Address
	 {
	    get { return _Address ; }
	    set { _Address = value ; }
	 }
	 public string Phone
	 {
	    get { return _Phone ; }
	    set { _Phone = value ; }
	 }
     public int NumberOfDevice
     {
         get { return _NumberOfDevice; }
         set { _NumberOfDevice = value; }
     }
	 public int UserGroupID
	 {
	    get { return _UserGroupID ; }
	    set { _UserGroupID = value ; }
	 }
	 public string CreateBy
	 {
	    get { return _CreateBy ; }
	    set { _CreateBy = value ; }
	 }
	 public string ModifyBy
	 {
	    get { return _ModifyBy ; }
	    set { _ModifyBy = value ; }
	 }
	 public DateTime CreateDate
	 {
	    get { return _CreateDate ; }
	    set { _CreateDate = value ; }
	 }
	 public DateTime ModifyDate
	 {
	    get { return _ModifyDate ; }
	    set { _ModifyDate = value ; }
	 }
	 public DateTime StartDate
	 {
	    get { return _StartDate ; }
	    set { _StartDate = value ; }
	 }
	 public DateTime EndDate
	 {
	    get { return _EndDate ; }
	    set { _EndDate = value ; }
	 }
	 public string Note
	 {
	    get { return _Note ; }
	    set { _Note = value ; }
	 }
	 public int Status
	 {
	    get { return _Status ; }
	    set { _Status = value ; }
	 }
     public string getUserType()
     {
         string result = "";
         string code = this.SecurityCode.Substring(0, 1);
         switch (code)
         {
             case "M":
                 result =  "Administrator";
                 break;
             case "G":
                 result = "Group";
                 break;
             case "U":
                 result = "User";
                 break;
         }
         return result;
     }
     
     public static EUserLogin createUser (DataRow row)
     {
         
         EUserLogin OUserLogin = new EUserLogin();     
        if (row["UserID"] != DBNull.Value)
            OUserLogin.UserID = (int)row["UserID"];
        if (row["Username"] != DBNull.Value)
            OUserLogin.Username = (string)row["Username"];
        if (row["Password"] != DBNull.Value)
        {
            OUserLogin.Password = (string)row["Password"];
            // OUserLogin.Password = GPSSecurity.DeCrypt(OUserLogin.Password, OUserLogin.Username);
        }
        if (row["SecurityCode"] != DBNull.Value)
            OUserLogin.SecurityCode = (string)row["SecurityCode"];
        if (row["Fullname"] != DBNull.Value)
            OUserLogin.Fullname = (string)row["Fullname"];
        if (row["Address"] != DBNull.Value)
            OUserLogin.Address = (string)row["Address"];
        if (row["Phone"] != DBNull.Value)
            OUserLogin.Phone = (string)row["Phone"];
        if (row["Cellphone"] != DBNull.Value)
            OUserLogin.Cellphone = (string)row["Cellphone"];
        if (row["TimeZoneMinute"] != DBNull.Value)
            OUserLogin.TimeZoneMinute = (int)row["TimeZoneMinute"];
        if (row["UserGroupID"] != DBNull.Value)
            OUserLogin.UserGroupID = (int)row["UserGroupID"];
        if (row["CreateBy"] != DBNull.Value)
            OUserLogin.CreateBy = (string)row["CreateBy"];
        if (row["ModifyBy"] != DBNull.Value)
            OUserLogin.ModifyBy = (string)row["ModifyBy"];
        if (row["CreateDate"] != DBNull.Value)
            OUserLogin.CreateDate = (DateTime)row["CreateDate"];
        if (row["ModifyDate"] != DBNull.Value)
            OUserLogin.ModifyDate = (DateTime)row["ModifyDate"];
        if (row["StartDate"] != DBNull.Value)
            OUserLogin.StartDate = (DateTime)row["StartDate"];
        if (row["EndDate"] != DBNull.Value)
            OUserLogin.EndDate = (DateTime)row["EndDate"];
        if (row["Note"] != DBNull.Value)
            OUserLogin.Note = (string)row["Note"];
        if (row["Email"] != DBNull.Value)
            OUserLogin.Email = (string)row["Email"];
        if (row["Status"] != DBNull.Value)
            OUserLogin.Status = (int)row["Status"];
        if (row["NumberOfDevice"] != DBNull.Value)
            OUserLogin.NumberOfDevice = (int)row["NumberOfDevice"];
        return OUserLogin;        
     }
   }
 }
